﻿using System;
using System.Collections.Generic;
using NUnit.Framework;
using RunAllTestsInSolutionTask;
using System.Collections;

namespace RunAllTestsInSolutionTaskTests
{

    [TestFixture]
    public class SolutionParserTests
    {
        [Test]
        public void GetAllTestProjects_SolutionWithNoTests_ReturnEmptyList()
        {
            var actual = SolutionParser.GetAllTestDlls(@"TestData\CustomTasks\CustomTasks.sln","Debug");
            Assert.IsEmpty(actual as ICollection);
        }

        [Test]
        public void GetAllTestProjects_NoneExistantSolution_ThrowException()
        {
            Assert.Throws<ArgumentException>
                (() => SolutionParser.GetAllTestDlls("NoSuchSLN.sln", "Debug"));
        }

        [Test]
        public void GetAllTestProjects_SolutionWithTestsDebugMode_ReturnAllTestDllsFromDebug()
        {
            var actual = SolutionParser.GetAllTestDlls(@"TestData\CTesting\Ctesting.sln", "Debug");
            var expected = new List<string>();
            expected.Add(@"TestData\CTesting\CTesting.AddinTests\bin\Debug\CTesting.AddinTests.dll");
            expected.Add(@"TestData\CTesting\Ctesting.AcceptanceTests\bin\Debug\Ctesting.AcceptanceTests.dll");
            expected.Add(@"TestData\CTesting\CTesting.TestRunnerUnitTests\bin\Debug\CTesting.TestRunnerUnitTests.dll");
            Assert.That(actual, Is.EquivalentTo(expected));
        }

        [Test]
        public void GetAllTestProjects_SolutionWithTestsReleaseMode_ReturnAllTestDllsFromRelease()
        {
            var actual = SolutionParser.GetAllTestDlls(@"TestData\CTesting\Ctesting.sln", "Release");
            var expected = new List<string>();
            expected.Add(@"TestData\CTesting\CTesting.AddinTests\bin\Release\CTesting.AddinTests.dll");
            expected.Add(@"TestData\CTesting\Ctesting.AcceptanceTests\bin\Release\Ctesting.AcceptanceTests.dll");
            expected.Add(@"TestData\CTesting\CTesting.TestRunnerUnitTests\bin\Release\CTesting.TestRunnerUnitTests.dll");
            Assert.That(actual, Is.EquivalentTo(expected));
        }

        [Test]
        public void GetAllTestsProjects_WithExcludes_ReturnAllProjectWithoutExcluded()
        {
            var actual = SolutionParser.GetAllTestDlls(@"TestData\CTesting\Ctesting.sln", 
                             "Release",
                             "CTesting.AddinTests.csproj");
            var expected = new List<string>();
            expected.Add(@"TestData\CTesting\Ctesting.AcceptanceTests\bin\Release\Ctesting.AcceptanceTests.dll");
            expected.Add(@"TestData\CTesting\CTesting.TestRunnerUnitTests\bin\Release\CTesting.TestRunnerUnitTests.dll");
            Assert.That(actual, Is.EquivalentTo(expected));
        }
    }
}


